package com.gitee.huanminabc.db_freedom.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.gitee.huanminabc.db_freedom.FreedomSqlInjector;
import com.gitee.huanminabc.db_freedom.interceptor.FreedomInterceptor;

import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

@Configuration(proxyBeanMethods = false)
//在MybatisPlusAutoConfiguration之前加载 ,因为内部sqlSessionFactory方法加载的时候会从容器中获取对应的拦截器和sql注入器\
//如果晚了就会导致mybatis plus执行的时候不会加载我们自定义的拦截器和sql注入器
@AutoConfigureBefore({MybatisPlusAutoConfiguration.class})
public class DbFreedomAutoConfiguration {

    /**
     * mybatis plus  拦截器
     */
    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE) //最高优先级,避免被其他三方库给覆盖了
    public FreedomInterceptor freedomInterceptor() {
        return new FreedomInterceptor();
    }

    /**
     * mybatis plus join 自定义方法
     */
    @Bean
    @Primary
    @Order(Ordered.HIGHEST_PRECEDENCE) //最高优先级,避免被其他三方库给覆盖了
    public FreedomSqlInjector freedomSqlInjector() {
        return new FreedomSqlInjector();
    }


}
